// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Security;

internal sealed partial class RoleDescriptorConverter : JsonConverter<RoleDescriptor>
{
	public override RoleDescriptor Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
	{
		if (reader.TokenType != JsonTokenType.StartObject)
			throw new JsonException("Unexpected JSON detected.");
		var variant = new RoleDescriptor();
		while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
		{
			if (reader.TokenType == JsonTokenType.PropertyName)
			{
				var property = reader.GetString();
				if (property == "applications")
				{
					variant.Applications = JsonSerializer.Deserialize<ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivileges>?>(ref reader, options);
					continue;
				}

				if (property == "cluster")
				{
					variant.Cluster = JsonSerializer.Deserialize<ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.ClusterPrivilege>?>(ref reader, options);
					continue;
				}

				if (property == "description")
				{
					variant.Description = JsonSerializer.Deserialize<string?>(ref reader, options);
					continue;
				}

				if (property == "indices" || property == "index")
				{
					variant.Indices = JsonSerializer.Deserialize<ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivileges>?>(ref reader, options);
					continue;
				}

				if (property == "metadata")
				{
					variant.Metadata = JsonSerializer.Deserialize<IDictionary<string, object>?>(ref reader, options);
					continue;
				}

				if (property == "run_as")
				{
					variant.RunAs = JsonSerializer.Deserialize<ICollection<string>?>(ref reader, options);
					continue;
				}

				if (property == "transient_metadata")
				{
					variant.TransientMetadata = JsonSerializer.Deserialize<IDictionary<string, object>?>(ref reader, options);
					continue;
				}
			}
		}

		return variant;
	}

	public override void Write(Utf8JsonWriter writer, RoleDescriptor value, JsonSerializerOptions options)
	{
		writer.WriteStartObject();
		if (value.Applications is not null)
		{
			writer.WritePropertyName("applications");
			JsonSerializer.Serialize(writer, value.Applications, options);
		}

		if (value.Cluster is not null)
		{
			writer.WritePropertyName("cluster");
			JsonSerializer.Serialize(writer, value.Cluster, options);
		}

		if (!string.IsNullOrEmpty(value.Description))
		{
			writer.WritePropertyName("description");
			writer.WriteStringValue(value.Description);
		}

		if (value.Indices is not null)
		{
			writer.WritePropertyName("indices");
			JsonSerializer.Serialize(writer, value.Indices, options);
		}

		if (value.Metadata is not null)
		{
			writer.WritePropertyName("metadata");
			JsonSerializer.Serialize(writer, value.Metadata, options);
		}

		if (value.RunAs is not null)
		{
			writer.WritePropertyName("run_as");
			JsonSerializer.Serialize(writer, value.RunAs, options);
		}

		if (value.TransientMetadata is not null)
		{
			writer.WritePropertyName("transient_metadata");
			JsonSerializer.Serialize(writer, value.TransientMetadata, options);
		}

		writer.WriteEndObject();
	}
}

[JsonConverter(typeof(RoleDescriptorConverter))]
public sealed partial class RoleDescriptor
{
	/// <summary>
	/// <para>
	/// A list of application privilege entries
	/// </para>
	/// </summary>
	public ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivileges>? Applications { get; set; }

	/// <summary>
	/// <para>
	/// A list of cluster privileges. These privileges define the cluster level actions that API keys are able to execute.
	/// </para>
	/// </summary>
	public ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.ClusterPrivilege>? Cluster { get; set; }

	/// <summary>
	/// <para>
	/// Optional description of the role descriptor
	/// </para>
	/// </summary>
	public string? Description { get; set; }

	/// <summary>
	/// <para>
	/// A list of indices permissions entries.
	/// </para>
	/// </summary>
	public ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivileges>? Indices { get; set; }

	/// <summary>
	/// <para>
	/// Optional meta-data. Within the metadata object, keys that begin with <c>_</c> are reserved for system usage.
	/// </para>
	/// </summary>
	public IDictionary<string, object>? Metadata { get; set; }

	/// <summary>
	/// <para>
	/// A list of users that the API keys can impersonate. <em>Note</em>: in Serverless, the run-as feature is disabled. For API compatibility, you can still specify an empty <c>run_as</c> field, but a non-empty list will be rejected.
	/// </para>
	/// </summary>
	public ICollection<string>? RunAs { get; set; }
	public IDictionary<string, object>? TransientMetadata { get; set; }
}

public sealed partial class RoleDescriptorDescriptor<TDocument> : SerializableDescriptor<RoleDescriptorDescriptor<TDocument>>
{
	internal RoleDescriptorDescriptor(Action<RoleDescriptorDescriptor<TDocument>> configure) => configure.Invoke(this);

	public RoleDescriptorDescriptor() : base()
	{
	}

	private ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivileges>? ApplicationsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivilegesDescriptor ApplicationsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivilegesDescriptor> ApplicationsDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivilegesDescriptor>[] ApplicationsDescriptorActions { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.ClusterPrivilege>? ClusterValue { get; set; }
	private string? DescriptionValue { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivileges>? IndicesValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivilegesDescriptor<TDocument> IndicesDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivilegesDescriptor<TDocument>> IndicesDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivilegesDescriptor<TDocument>>[] IndicesDescriptorActions { get; set; }
	private IDictionary<string, object>? MetadataValue { get; set; }
	private ICollection<string>? RunAsValue { get; set; }
	private IDictionary<string, object>? TransientMetadataValue { get; set; }

	/// <summary>
	/// <para>
	/// A list of application privilege entries
	/// </para>
	/// </summary>
	public RoleDescriptorDescriptor<TDocument> Applications(ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivileges>? applications)
	{
		ApplicationsDescriptor = null;
		ApplicationsDescriptorAction = null;
		ApplicationsDescriptorActions = null;
		ApplicationsValue = applications;
		return Self;
	}

	public RoleDescriptorDescriptor<TDocument> Applications(Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivilegesDescriptor descriptor)
	{
		ApplicationsValue = null;
		ApplicationsDescriptorAction = null;
		ApplicationsDescriptorActions = null;
		ApplicationsDescriptor = descriptor;
		return Self;
	}

	public RoleDescriptorDescriptor<TDocument> Applications(Action<Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivilegesDescriptor> configure)
	{
		ApplicationsValue = null;
		ApplicationsDescriptor = null;
		ApplicationsDescriptorActions = null;
		ApplicationsDescriptorAction = configure;
		return Self;
	}

	public RoleDescriptorDescriptor<TDocument> Applications(params Action<Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivilegesDescriptor>[] configure)
	{
		ApplicationsValue = null;
		ApplicationsDescriptor = null;
		ApplicationsDescriptorAction = null;
		ApplicationsDescriptorActions = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// A list of cluster privileges. These privileges define the cluster level actions that API keys are able to execute.
	/// </para>
	/// </summary>
	public RoleDescriptorDescriptor<TDocument> Cluster(ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.ClusterPrivilege>? cluster)
	{
		ClusterValue = cluster;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Optional description of the role descriptor
	/// </para>
	/// </summary>
	public RoleDescriptorDescriptor<TDocument> Description(string? description)
	{
		DescriptionValue = description;
		return Self;
	}

	/// <summary>
	/// <para>
	/// A list of indices permissions entries.
	/// </para>
	/// </summary>
	public RoleDescriptorDescriptor<TDocument> Indices(ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivileges>? indices)
	{
		IndicesDescriptor = null;
		IndicesDescriptorAction = null;
		IndicesDescriptorActions = null;
		IndicesValue = indices;
		return Self;
	}

	public RoleDescriptorDescriptor<TDocument> Indices(Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivilegesDescriptor<TDocument> descriptor)
	{
		IndicesValue = null;
		IndicesDescriptorAction = null;
		IndicesDescriptorActions = null;
		IndicesDescriptor = descriptor;
		return Self;
	}

	public RoleDescriptorDescriptor<TDocument> Indices(Action<Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivilegesDescriptor<TDocument>> configure)
	{
		IndicesValue = null;
		IndicesDescriptor = null;
		IndicesDescriptorActions = null;
		IndicesDescriptorAction = configure;
		return Self;
	}

	public RoleDescriptorDescriptor<TDocument> Indices(params Action<Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivilegesDescriptor<TDocument>>[] configure)
	{
		IndicesValue = null;
		IndicesDescriptor = null;
		IndicesDescriptorAction = null;
		IndicesDescriptorActions = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Optional meta-data. Within the metadata object, keys that begin with <c>_</c> are reserved for system usage.
	/// </para>
	/// </summary>
	public RoleDescriptorDescriptor<TDocument> Metadata(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
	{
		MetadataValue = selector?.Invoke(new FluentDictionary<string, object>());
		return Self;
	}

	/// <summary>
	/// <para>
	/// A list of users that the API keys can impersonate. <em>Note</em>: in Serverless, the run-as feature is disabled. For API compatibility, you can still specify an empty <c>run_as</c> field, but a non-empty list will be rejected.
	/// </para>
	/// </summary>
	public RoleDescriptorDescriptor<TDocument> RunAs(ICollection<string>? runAs)
	{
		RunAsValue = runAs;
		return Self;
	}

	public RoleDescriptorDescriptor<TDocument> TransientMetadata(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
	{
		TransientMetadataValue = selector?.Invoke(new FluentDictionary<string, object>());
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (ApplicationsDescriptor is not null)
		{
			writer.WritePropertyName("applications");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, ApplicationsDescriptor, options);
			writer.WriteEndArray();
		}
		else if (ApplicationsDescriptorAction is not null)
		{
			writer.WritePropertyName("applications");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivilegesDescriptor(ApplicationsDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (ApplicationsDescriptorActions is not null)
		{
			writer.WritePropertyName("applications");
			writer.WriteStartArray();
			foreach (var action in ApplicationsDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivilegesDescriptor(action), options);
			}

			writer.WriteEndArray();
		}
		else if (ApplicationsValue is not null)
		{
			writer.WritePropertyName("applications");
			JsonSerializer.Serialize(writer, ApplicationsValue, options);
		}

		if (ClusterValue is not null)
		{
			writer.WritePropertyName("cluster");
			JsonSerializer.Serialize(writer, ClusterValue, options);
		}

		if (!string.IsNullOrEmpty(DescriptionValue))
		{
			writer.WritePropertyName("description");
			writer.WriteStringValue(DescriptionValue);
		}

		if (IndicesDescriptor is not null)
		{
			writer.WritePropertyName("indices");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, IndicesDescriptor, options);
			writer.WriteEndArray();
		}
		else if (IndicesDescriptorAction is not null)
		{
			writer.WritePropertyName("indices");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivilegesDescriptor<TDocument>(IndicesDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (IndicesDescriptorActions is not null)
		{
			writer.WritePropertyName("indices");
			writer.WriteStartArray();
			foreach (var action in IndicesDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivilegesDescriptor<TDocument>(action), options);
			}

			writer.WriteEndArray();
		}
		else if (IndicesValue is not null)
		{
			writer.WritePropertyName("indices");
			JsonSerializer.Serialize(writer, IndicesValue, options);
		}

		if (MetadataValue is not null)
		{
			writer.WritePropertyName("metadata");
			JsonSerializer.Serialize(writer, MetadataValue, options);
		}

		if (RunAsValue is not null)
		{
			writer.WritePropertyName("run_as");
			JsonSerializer.Serialize(writer, RunAsValue, options);
		}

		if (TransientMetadataValue is not null)
		{
			writer.WritePropertyName("transient_metadata");
			JsonSerializer.Serialize(writer, TransientMetadataValue, options);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class RoleDescriptorDescriptor : SerializableDescriptor<RoleDescriptorDescriptor>
{
	internal RoleDescriptorDescriptor(Action<RoleDescriptorDescriptor> configure) => configure.Invoke(this);

	public RoleDescriptorDescriptor() : base()
	{
	}

	private ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivileges>? ApplicationsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivilegesDescriptor ApplicationsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivilegesDescriptor> ApplicationsDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivilegesDescriptor>[] ApplicationsDescriptorActions { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.ClusterPrivilege>? ClusterValue { get; set; }
	private string? DescriptionValue { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivileges>? IndicesValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivilegesDescriptor IndicesDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivilegesDescriptor> IndicesDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivilegesDescriptor>[] IndicesDescriptorActions { get; set; }
	private IDictionary<string, object>? MetadataValue { get; set; }
	private ICollection<string>? RunAsValue { get; set; }
	private IDictionary<string, object>? TransientMetadataValue { get; set; }

	/// <summary>
	/// <para>
	/// A list of application privilege entries
	/// </para>
	/// </summary>
	public RoleDescriptorDescriptor Applications(ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivileges>? applications)
	{
		ApplicationsDescriptor = null;
		ApplicationsDescriptorAction = null;
		ApplicationsDescriptorActions = null;
		ApplicationsValue = applications;
		return Self;
	}

	public RoleDescriptorDescriptor Applications(Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivilegesDescriptor descriptor)
	{
		ApplicationsValue = null;
		ApplicationsDescriptorAction = null;
		ApplicationsDescriptorActions = null;
		ApplicationsDescriptor = descriptor;
		return Self;
	}

	public RoleDescriptorDescriptor Applications(Action<Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivilegesDescriptor> configure)
	{
		ApplicationsValue = null;
		ApplicationsDescriptor = null;
		ApplicationsDescriptorActions = null;
		ApplicationsDescriptorAction = configure;
		return Self;
	}

	public RoleDescriptorDescriptor Applications(params Action<Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivilegesDescriptor>[] configure)
	{
		ApplicationsValue = null;
		ApplicationsDescriptor = null;
		ApplicationsDescriptorAction = null;
		ApplicationsDescriptorActions = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// A list of cluster privileges. These privileges define the cluster level actions that API keys are able to execute.
	/// </para>
	/// </summary>
	public RoleDescriptorDescriptor Cluster(ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.ClusterPrivilege>? cluster)
	{
		ClusterValue = cluster;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Optional description of the role descriptor
	/// </para>
	/// </summary>
	public RoleDescriptorDescriptor Description(string? description)
	{
		DescriptionValue = description;
		return Self;
	}

	/// <summary>
	/// <para>
	/// A list of indices permissions entries.
	/// </para>
	/// </summary>
	public RoleDescriptorDescriptor Indices(ICollection<Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivileges>? indices)
	{
		IndicesDescriptor = null;
		IndicesDescriptorAction = null;
		IndicesDescriptorActions = null;
		IndicesValue = indices;
		return Self;
	}

	public RoleDescriptorDescriptor Indices(Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivilegesDescriptor descriptor)
	{
		IndicesValue = null;
		IndicesDescriptorAction = null;
		IndicesDescriptorActions = null;
		IndicesDescriptor = descriptor;
		return Self;
	}

	public RoleDescriptorDescriptor Indices(Action<Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivilegesDescriptor> configure)
	{
		IndicesValue = null;
		IndicesDescriptor = null;
		IndicesDescriptorActions = null;
		IndicesDescriptorAction = configure;
		return Self;
	}

	public RoleDescriptorDescriptor Indices(params Action<Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivilegesDescriptor>[] configure)
	{
		IndicesValue = null;
		IndicesDescriptor = null;
		IndicesDescriptorAction = null;
		IndicesDescriptorActions = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Optional meta-data. Within the metadata object, keys that begin with <c>_</c> are reserved for system usage.
	/// </para>
	/// </summary>
	public RoleDescriptorDescriptor Metadata(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
	{
		MetadataValue = selector?.Invoke(new FluentDictionary<string, object>());
		return Self;
	}

	/// <summary>
	/// <para>
	/// A list of users that the API keys can impersonate. <em>Note</em>: in Serverless, the run-as feature is disabled. For API compatibility, you can still specify an empty <c>run_as</c> field, but a non-empty list will be rejected.
	/// </para>
	/// </summary>
	public RoleDescriptorDescriptor RunAs(ICollection<string>? runAs)
	{
		RunAsValue = runAs;
		return Self;
	}

	public RoleDescriptorDescriptor TransientMetadata(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
	{
		TransientMetadataValue = selector?.Invoke(new FluentDictionary<string, object>());
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (ApplicationsDescriptor is not null)
		{
			writer.WritePropertyName("applications");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, ApplicationsDescriptor, options);
			writer.WriteEndArray();
		}
		else if (ApplicationsDescriptorAction is not null)
		{
			writer.WritePropertyName("applications");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivilegesDescriptor(ApplicationsDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (ApplicationsDescriptorActions is not null)
		{
			writer.WritePropertyName("applications");
			writer.WriteStartArray();
			foreach (var action in ApplicationsDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Security.ApplicationPrivilegesDescriptor(action), options);
			}

			writer.WriteEndArray();
		}
		else if (ApplicationsValue is not null)
		{
			writer.WritePropertyName("applications");
			JsonSerializer.Serialize(writer, ApplicationsValue, options);
		}

		if (ClusterValue is not null)
		{
			writer.WritePropertyName("cluster");
			JsonSerializer.Serialize(writer, ClusterValue, options);
		}

		if (!string.IsNullOrEmpty(DescriptionValue))
		{
			writer.WritePropertyName("description");
			writer.WriteStringValue(DescriptionValue);
		}

		if (IndicesDescriptor is not null)
		{
			writer.WritePropertyName("indices");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, IndicesDescriptor, options);
			writer.WriteEndArray();
		}
		else if (IndicesDescriptorAction is not null)
		{
			writer.WritePropertyName("indices");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivilegesDescriptor(IndicesDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (IndicesDescriptorActions is not null)
		{
			writer.WritePropertyName("indices");
			writer.WriteStartArray();
			foreach (var action in IndicesDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Security.IndicesPrivilegesDescriptor(action), options);
			}

			writer.WriteEndArray();
		}
		else if (IndicesValue is not null)
		{
			writer.WritePropertyName("indices");
			JsonSerializer.Serialize(writer, IndicesValue, options);
		}

		if (MetadataValue is not null)
		{
			writer.WritePropertyName("metadata");
			JsonSerializer.Serialize(writer, MetadataValue, options);
		}

		if (RunAsValue is not null)
		{
			writer.WritePropertyName("run_as");
			JsonSerializer.Serialize(writer, RunAsValue, options);
		}

		if (TransientMetadataValue is not null)
		{
			writer.WritePropertyName("transient_metadata");
			JsonSerializer.Serialize(writer, TransientMetadataValue, options);
		}

		writer.WriteEndObject();
	}
}